import pytest
from pytest_demo.Calculator import Calculator
import os
import yaml

@pytest.fixture()
def initcal_class():
    print("----------------开始计算--------------")
    cal = Calculator()
    yield cal
    print("***************计算结束*****************")


def get_yaml_datas():
    yaml_path = os.path.join(os.path.join(os.path.split(os.path.realpath(__file__))[0], "datas"), "cal.yaml")
    with open(yaml_path) as f:
        datas = yaml.safe_load(f)
        return datas


# 调用get_datas()方法，使用fixture返回get_datasd方法中的数据
@pytest.fixture(params=get_yaml_datas()["int_datas"], ids=get_yaml_datas()["ids_int_datas"])
def get_params(request):
    return request.param


def test_get_params(get_params):
    print(get_params)


def pytest_collection_modifyitems(session, config, items):
    print("这是收集所有测试用例的方法")
    print(items)


def test_pytest_collection_modifyitems(pytest_collection_modifyitems):
    print(pytest_collection_modifyitems)
